#!/usr/bin/python3

import os
import sys

import pyglet
from pyglet import image
from pyglet.gl import *
from pyglet.sprite import Sprite
from pyglet.text import Label
from pyglet.window import key, mouse

win = pyglet.window.Window(width=800, height=600, caption='开始页面')
win.set_icon(image.load('logo.png'))
l1 = Label('pyglet 教程第%s课' % sys.argv[1], x=win.width / 2, y=win.height * 0.7,
        anchor_x='center', anchor_y='center', font_size=50)
l2 = Label(sys.argv[2], x=win.width / 2, y=win.height * 0.58,
        anchor_x='center', anchor_y='center', font_size=35)
img = image.load('logo.png')
img.anchor_x= 105
img.anchor_y= 210

@win.event
def on_mouse_press(x, y, btn, mod):
    pass

@win.event
def on_resize(w, h):
    l1.x = w / 2
    l1.y = h * 0.7
    l2.x = w / 2
    l2.y = h * 0.58

@win.event
def on_draw():
    win.clear()
    l1.draw()
    l2.draw()
    img.blit(win.width / 2, win.height * 0.4)

@win.event
def on_key_press(sym, mod):
    if sym == key.ENTER:
        win.close()
        os.system('idle')
    elif sym == key.F2:
        image.get_buffer_manager().get_color_buffer().save('screenshot.png')

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glClearColor(0.5, 0.69, 1.0, 1)
pyglet.app.run()
